home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / CellScrollView.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  3.8 KB  |  171 lines

  1. /*
  2.  *  Copyright (C) 1993  Robert Davis
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of Version 2, or any later version, of 
  6.  *  the GNU General Public License as published by the Free Software 
  7.  *  Foundation.
  8.  */
  9.  
  10. static char RCSId[]="$Id: CellScrollView.m,v 1.9 1993/05/18 03:54:44 davis Exp $";
  11.  
  12.  
  13. /*
  14.  *  Based heavily on the NeXTSTEP MiniExample CellScrollView
  15.  *  by R. Dunbar Poor and Mai Nguyen.
  16.  */
  17.  
  18. #import <appkit/Cell.h>
  19. #import <appkit/nextstd.h>
  20.  
  21. #import "CellScrollView.h"
  22. #import "EditMatrix.h"
  23. #import "SubObjectCategory.h"
  24.  
  25. @implementation CellScrollView
  26.  
  27. - initFrame:(const NXRect *)frameRect
  28. {
  29.     [super initFrame:frameRect];
  30.     return self;
  31. }
  32.  
  33.  
  34. - initMatrixCellClass:classId cols:(int)anInt
  35. {
  36.     Cell    *cell;
  37.     NXSize    interCellSpacing = {0.0, 0.0};
  38.  
  39.     /* 
  40.      *  This method should only be called once.  Check to see if 
  41.      *  cellMatrix already exists.
  42.      */
  43.     if (cellMatrix || !classId)
  44.     return nil;
  45.  
  46.     cell = [[classId alloc] init];
  47.     isSubType = [cell respondsTo:@selector(setSubObject:)];
  48.     [cell free];
  49.  
  50.     numCols = anInt;
  51.  
  52.     cellMatrix = [[EditMatrix alloc] initFrame: &frame
  53.                       mode: NX_LISTMODE
  54.                      cellClass: (cellClass = classId)
  55.                        numRows: 0
  56.                        numCols: numCols];
  57.  
  58.     [cellMatrix setIntercell:&interCellSpacing];
  59.     [cellMatrix sizeToCells];        /* Resize matrix to contain cells    */
  60.     [cellMatrix setAutosizeCells:YES];
  61.  
  62.     [cellMatrix setAutoscroll:YES];    /* Auto-scroll on drag if necessary  */
  63.     [cellMatrix setAutosizing:NX_WIDTHSIZABLE];
  64.  
  65.     [[self setDocView:cellMatrix] free];
  66.  
  67.     [self setVertScrollerRequired:YES];
  68.     [self setBorderType:NX_BEZEL];
  69.     [self setAutoresizeSubviews:YES];
  70.     /* This is the only way to get the clipview to resize too */
  71.     [[cellMatrix superview] setAutoresizeSubviews:YES];
  72.  
  73.     if (cellSizePrototype) {
  74.     NXRect    protoFrame;
  75.     NXSize    docSize;
  76.  
  77.     [cellSizePrototype getFrame:&protoFrame];
  78.     [self getContentSize:&docSize];
  79.  
  80.     if ((NX_WIDTH(&protoFrame) * numCols) > docSize.width)
  81.         [self setHorizScrollerRequired:YES];
  82.  
  83.     [cellMatrix sizeTo:(NX_WIDTH(&protoFrame) * numCols) :docSize.height];
  84.     [cellSizePrototype free];
  85.     cellSizePrototype = nil;
  86.     } else {
  87.     NXSize    docSize;
  88.     /* Resize the matrix to fill the inside of the scrollview */
  89.  
  90.     [self getContentSize:&docSize];
  91.     [cellMatrix sizeTo:docSize.width :docSize.height];
  92.     }
  93.  
  94.     return self;
  95. }
  96.  
  97.  
  98. - free
  99. {
  100.     [cellMatrix free];
  101.     return [super free];
  102. }
  103.  
  104.  
  105. - awakeFromNib
  106. {
  107.     return self;
  108. }
  109.  
  110.  
  111. - cellMatrix
  112. {
  113.   return cellMatrix;
  114. }
  115.  
  116.  
  117. - loadCol:(int)col from:(List *)cellObjects
  118. /*
  119.  *  Fill column col of the matrix with Cells, associate each Cell with 
  120.  *  a cellObject.
  121.  *
  122.  *  Since we recycle the cells (via renewRows:cols:), we also set the 
  123.  *  state of each cell to 0 and unhighlight it.  If we don't do that, 
  124.  *  the recycled cells will display their previous state.
  125.  */
  126. {
  127.     int i, cellCount;
  128.  
  129.     if (!isSubType)
  130.     return nil;
  131.  
  132.     cellCount = [cellObjects count];
  133.  
  134.     if (col > numCols)
  135.     numCols = col + 1;
  136.  
  137.     /* tell the matrix there are 0 cells in it (but don't deallocate them) */
  138.     [cellMatrix renewRows:0 cols:numCols];
  139.     [cellMatrix lockFocus];               /* for highlightCellAt::lit: */
  140.     for (i=0; i < cellCount; i++) {
  141.     id cell;
  142.     /*
  143.      *  Add a row to the matrix.  (This doesn't necessarily 
  144.      *  allocate a new cell, thanks to renewRows:cols:).
  145.      */
  146.     [cellMatrix addRow];
  147.     cell = [cellMatrix cellAt:i:col];
  148.     /* install the cellObject in that cell */
  149.     [cell setSubObject:[cellObjects objectAt:i]];
  150.     /* make sure the cell is neither selected nor highlighted */
  151.     [cellMatrix highlightCellAt:i:0 lit:NO];
  152.     [cell setState:0];
  153.     }
  154.     [cellMatrix unlockFocus];
  155.     [cellMatrix sizeToCells];
  156.     [cellMatrix display];
  157.   
  158.     return self;
  159. }
  160.  
  161.  
  162.  
  163. // Shuts up the compiler about unused RCSId
  164. - (const char *) rcsid
  165. {
  166.     return RCSId;
  167. }
  168.  
  169.  
  170. @end
  171.